package net.zjitc.android2019.ch2activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import net.zjitc.android2019.R;

public class RegisterActivity extends AppCompatActivity {
    /* 定义控件属性（布局文件中相关的控件）*/
    private EditText ed_name,ed_phone;
    private Button btn_submit,btn_reset;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /* 1、关联布局文件*/
        setContentView(R.layout.linear2);
        /* 2、关联控件*/
        ed_name=findViewById(R.id.editText);
        ed_phone=findViewById(R.id.editText2);
        btn_submit=findViewById(R.id.button3);
        btn_reset=findViewById(R.id.btn_reset);

        /* 3、按钮的点击事件*/

        /* 事件*/
        View.OnClickListener click=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /* 判断点击的是哪个按钮 */
                switch (v.getId()){
                    case R.id.button3:
                        String s=ed_name.getText().toString()+"  "+ed_phone.getText().toString();

                        Toast.makeText(RegisterActivity.this, s, Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.btn_reset:
                        ed_name.setText("");
                        ed_phone.setText("");
                        /* 让ed_name获取焦点*/
                        ed_name.requestFocus();
                        break;
                }
            }
        };

        /* 按钮绑定上事件*/
        btn_submit.setOnClickListener(click);
        btn_reset.setOnClickListener(click);

    }
}
